<?php
/**
 * User: hjd-yao
 * Date: 2019/5/9
 * Time: 12:54
 */

namespace App\Http\Controllers\User;


use App\Helpers\Search;
use App\Helpers\SelfResponse;
use App\Http\Controllers\BackendController;
use Carbon\Carbon;
use DC\UserCenter\Models\UserBaseModel;
use Illuminate\Http\Request;

use App\Models\Shop\UpgradeModel;
use App\Models\Shop\UpgradeInfoModel;


class UpgradeController extends BackendController
{

    /**
     * @title 升级记录
     * @param Request $request
     * @return View
     */
    public function upRecord(Request $request)
    {
        $search = Search::make($request)->bindModel(UpgradeModel::with('user')->has('user'))
            ->input('user','编号/姓名/手机号','',['field'=>'user_id'])
            ->time('created_at','申请时间')
            ->bindSearchData()->relationModel(['user'=>function($value){
                return UserBaseModel::where('user_number',$value)
                    ->orWhere('real_name',$value)->orWhere('user_phone',$value)->pluck('member_id')->toArray();
            }]);
        $list = $search->where()->whereIn('status',[2,3])->orderBy('created_at','desc')
            ->paginate($this->getPerPageNum());

        return view('backend::upgrade.up_record',[
            'page_title'=>'升级记录',
            'list'=>$list,
            'search'=>$search
        ]);
    }


    /**
     * @title 升级申请
     * @param Request $request
     * @return View
     */
    public function upApply(Request $request)
    {
        $search = Search::make($request)->bindModel(UpgradeModel::with('user')->has('user'))
            ->input('user','编号/姓名/手机号','',['field'=>'user_id'])
            ->time('created_at','申请时间')
            ->bindSearchData()->relationModel(['user'=>function($value){
                return UserBaseModel::where('user_number',$value)
                    ->orWhere('real_name',$value)->orWhere('user_phone',$value)->pluck('member_id')->toArray();
            }]);

        $list = $search->where()->where('status',1)->orderBy('created_at','desc')
            ->paginate($this->getPerPageNum());

        return view('backend::upgrade.up_apply',[
            'page_title'=>'升级申请',
            'list'=>$list,
            'search'=>$search
        ]);
    }

    /**
     * @title 升级详情
     * @param $wd_id
     * @return View
     */
    public function detail($id)
    {
        $info = UpgradeModel::with('user')->find($id);

        $info['up_info'] = UpgradeInfoModel::init()->with('HandUser','HandUserInfo')->where('upgrade_id',$id)->get();

        return view('backend::upgrade.up_detail',[
            'page_title'=>'升级详情',
            'info'=>$info
        ]);
    }


}